package com.personal.service.impl;

import com.personal.dao.ParkAreaDao;
import com.personal.domain.ParkArea;
import com.personal.domain.obtain.ParkAreaDireTree;
import com.personal.service.ParkAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @projectName: smartCommunity_springboot
 * @package: com.personal.service.impl
 * @className: ParkAreaServiceImpl
 * @author: bong~
 * @description: TODO
 * @date: 2023/8/11 14:35
 * @version: 1.0
 */

@Service
public class ParkAreaServiceImpl implements ParkAreaService {

    @Autowired
    private ParkAreaDao parkAreaDao;


    @Override
    public List<ParkArea> selectPart() {
        return parkAreaDao.selectAll();
    }



    @Override
    public List<ParkAreaDireTree> getDirectoryTree(Integer parentId) {

        List<ParkAreaDireTree> directories=new ArrayList<>();

        List<ParkArea> list=parkAreaDao.selectByParentId(parentId);

        for(ParkArea cur:list){
            int id=cur.getId();
            int curParentId=cur.getParentId();
            String name=cur.getName();
            int status=cur.getStatus();
            String path=cur.getPath();

            ParkAreaDireTree directory=new ParkAreaDireTree(id,curParentId,name,status,path);
            List<ParkAreaDireTree> subDirectory=getDirectoryTree(id);
            directory.setSubDirectory(subDirectory);


            directories.add(directory);

        }
        return directories;


    }
}
